<?php
	require_once('Response.php');
	require_once('KunakiProduct.php');
	require_once('ShippingRequest.php');
	require_once('ShippingResponse.php');
	require_once('OrderRequest.php');
	require_once('OrderResponse.php');
	require_once('Response.php');
	
	$Kunaki_user = 'username';
	$Kunaki_pass = 'password';
	
	class Kunaki{
		public static function getShippingOptions($request){
			return Kunaki::getXMLResponse($request);
		}	
		
		public static function placeOrder($request){
			return Kunaki::getXMLResponse($request);
		}
		
		public static function getXMLResponse($request_object){
			$request = '<?xml version="1.0"?>' . "\n";
			$request .= $request_object->getXML();
			$header[] = "Host: Kunaki.com";
			$header[] = "Content-type: text/xml";
			$header[] = "Content-length: ".strlen($request) . "\r\n";
			
			$ch = curl_init();
			curl_setopt( $ch, CURLOPT_URL, "http://kunaki.com/XMLService.ASP"); # URL to post to
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
			curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above
			curl_setopt( $ch, CURLOPT_POSTFIELDS, $request );
			curl_setopt( $ch, CURLOPT_POST, true );
			$response = curl_exec( $ch );
			curl_close($ch); 
			return new $request_object->response_type($response);
		}	
	}
?>
